home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3937 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: howland.reston.ans.net!usc!usc!not-for-mail
  2. From: wawda@alcor.usc.edu (Abu Wawda)
  3. Newsgroups: comp.lang.c
  4. Subject: Got Questions About Multi-Dimension Arrays (After Reading FAQ)
  5. Date: 31 Jan 1996 18:23:39 -0800
  6. Organization: University of Southern California, Los Angeles, CA
  7. Sender: wawda@alcor.usc.edu
  8. Distribution: world
  9. Message-ID: <4ep87b$o60@alcor.usc.edu>
  10. NNTP-Posting-Host: alcor.usc.edu
  11.  
  12. I read questions 6.19 and 6.20 from the FAQ that deal with
  13. multi-dimensional arrays but am still confused. If someone can clear
  14. up my confusion, I would really appreciate it. Bascailly I still don't
  15. see why it isn't possible to do this:
  16.  
  17. void myfunc(int *array,int rows,int cols)
  18. {
  19.    printf("%d\n",array[1][1]);
  20.  
  21. and call the function like this:
  22.  
  23. int m[2][2] = {1, 2, 3, 4};
  24.  
  25. myfunc(m,2,2);
  26.  
  27. If I understand correctly, a multideminsional array is really stored
  28. continguously like this in memory:
  29.  
  30. array[0][0]    | 1 | memory address a
  31. array[0][1]    | 2 | memory address a+sizeof(int)
  32. array[1][0]    | 3 | ....
  33. array[1][1]    | 4 | ....
  34.  
  35. So why can't C convert from pointer to integer to a multidemsional
  36. array. The reason I want to do this is because my function needs to
  37. take in an array of any width and height. Thank you for your time,
  38.  
  39. Abu Wawda
  40. wawda@scf.usc.edu
  41.